import java.util.Scanner;

public class 特别数的和 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += judgeNum(i);
        }
        System.out.println(sum);
    }

    private static int judgeNum(int num) {
        //判断这个数是不是包含2,0,1,9
        String s = String.valueOf(num);
        //一个一个判断
        int length = s.length();
        for (int i = 0; i < length; i++) {
            if (s.charAt(i) == '2' || s.charAt(i) == '0' || s.charAt(i) == '1' || s.charAt(i) == '9')
                return num;
        }
        //System.out.println("这些数为："+num);
        return 0;
    }
}
